<?php
namespace app\api\validate;
use app\lib\exception\ParameterException;
use think\facade\Request;
use think\Validate;

/**
 * Created by PhpStorm.
 * User: muyu
 * Date: 2018/1/23
 * Time: 22:35
 * 验证器基类
 */
class BaseValidate extends Validate{
    protected $batchValidate = true;
    public function goCheck(){
       //获取所有参数
       //对这些参数做检验
        $request = Request::instance();
        $params = $request->param();

        $result = $this->batch()
            ->check($params);
        if (!$result)
        {
            $e = new ParameterException(
                [
                    'msg' => $this->error,
                ]);
            throw $e;
        }
        else
        {
            return true;
        }
   }
    protected function isPositiveInteger(
        $value, $rule = '',
        $data = '', $field = '')
    {
        if (is_numeric($value) && is_int($value + 0) && ($value + 0) > 0)
        {
            return true;
        }
        else
        {
            return false;
            //            return $field.'必须是正整数';
        }
    }

}